<template>
  <view>
    <!-- 1.1 搜索框 开始 -->
    <YgSearch></YgSearch>
    <!-- 1.1 搜索框 结束 -->

    <!-- 2.1轮播图 -->
    <u-swiper height="340" :list="swiperList" name="image_src"></u-swiper>
    <!-- 2.1轮播图结束 -->

    <!-- 3.1导航开始 -->
    <view class="catitem u-flex">
      <navigator
        class="u-flex-1 u-padding-30"
        v-for="item in catitems"
        :key="item.name"
      >
        <u-image width="100%" mode="widthFix" :src="item.image_src"></u-image>
      </navigator>
    </view>
    <!-- 3.1导航结束 -->

    <!-- 4.1楼层开始 -->
    <view class="floor">
      <view class="floor-group" v-for="(item1, index1) in floora" :key="index1">
        <view class="group-title">
          <u-image
            mode="widthFix"
            width="100%"
            :src="item1.floor_title.image_src"
          ></u-image>
        </view>

        <view class="group-content">
          <navigator
            v-for="(item2, index2) in item1.product_list"
            :key="item2.name"
          >
            <u-image
              height="100%"
              :mode="index2 === 0 ? 'widthFix' : 'scaleToFill'"
              :src="item2.image_src"
            ></u-image>
          </navigator>
        </view>
      </view>
    </view>
    <!-- 4.1楼层结束 -->
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 轮播图数组
      swiperList: [],
      catitems: [],
      floora: [],
    };
  },

  async onLoad() {
    //1.1
    // const [err, res] = await uni.request({
    //   url: "https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
    // });
    // this.swiperList = res.data.message;

    const res = await this.$u.get("/home/swiperdata");
    this.swiperList = res.message;

    //导航
    const resCate = await this.$u.get("/home/catitems");
    this.catitems = resCate.message;

    //楼层
    const resFloor = await this.$u.get("/home/floordata");
    this.floora = resFloor.message;
  },
};
</script>

<style lang="scss">
/* 楼层 */
.floor {
  .floor-group {
    .group-title {
      padding: 10rpx;
    }
    .group-content {
      overflow: hidden;
      navigator {
        float: left;
        width: 33.33%;
        border: 3rpx solid #fff;
        &:nth-last-child(-n + 4) {
          // 后四个
          height: 208rpx;
          image {
            height: 100%;
          }
        }
      }
    }
  }
}
</style>
